﻿namespace SsisLdapSource.InstantiationTime
{
    using System.DirectoryServices.Protocols;
    using System.Net.NetworkInformation;

    using global::SsisLdapSource.DirectoryServicesProtocolsExtensions;

    public static class CustomPropertiesDefaultValueFactory
    {
        static CustomPropertiesDefaultValueFactory()
        {
            try
            {
                DomainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
            }
            catch (NetworkInformationException)
            {
                DomainName = string.Empty;
            }
        }

        public static string DomainName { get; private set; }

        public static string GetBaseDN()
        {
            return string.IsNullOrEmpty(DomainName) ? string.Empty : 
                (new LdapConnection(DomainName)).GetDefaultNamingContextDN();
        }
    }
}
